package com.ddwl.goods.dao;

import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.dao.TkDao;
import com.ddwl.goods.dao.model.Academy;
import com.ddwl.goods.mapper.ColumnEssayMapper;
import com.ddwl.goods.model.ColumnEssay;
import com.ddwl.schema.bo.goods.ColumnEssayPageBo;
import com.ddwl.schema.vo.goods.AcademyColumnEssayVo;
import com.ddwl.schema.vo.goods.AcademyVo;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author hemiaojun
 * @Date 2020/11/19 18:28
 */
@Repository
public class ColumnEssayDao extends TkDao<ColumnEssayMapper, ColumnEssay> {

    @Resource
    private ColumnEssayMapper columnEssayMapper;

    public List<Academy> getEssayByColumnId(String columnId) {
        return columnEssayMapper.getEssayByColumnId(columnId);
    }

    public List<AcademyColumnEssayVo> getAcademyColumnEssay() {
        return columnEssayMapper.getAcademyColumnEssay();
    }

    public void batchInsert(List<ColumnEssay> columnEssays){
        columnEssayMapper.batchInsert(columnEssays);
    }

    public List<AcademyVo> getColumnEssayList(ColumnEssayPageBo param) {
        return columnEssayMapper.getColumnEssayList(param);
    }

    public void deleteColumnEssayByEssayId(String essayId) {
        ColumnEssay columnEssay = new ColumnEssay();
        columnEssay.setDflag(BaseEnum.DflagEnum.DELETED.getCode());
        Example example = getExample();
        example.and().andEqualTo("essayId", essayId);
        columnEssayMapper.updateByExampleSelective(columnEssay,example);
    }

    public void essaySort(ColumnEssay columnEssay) {
        ColumnEssay entity = new ColumnEssay();
        entity.setSort(columnEssay.getSort());
        Example example = getExample();
        example.and().andEqualTo("essayId", columnEssay.getEssayId())
                .andEqualTo("academyColumnId", columnEssay.getAcademyColumnId());
        columnEssayMapper.updateByExampleSelective(entity,example);
    }
}
